<template>
  <div class="ChildPage TablePage" v-loading="loading">
    <vb-page ref="page" @onTableSelection="doSelect">
      <template #table-rfid1="scope">
        {{ (scope.row.rfid && scope.row.rfid.length > 0)? scope.row.rfid[0]: '' }}
      </template>
      <template #table-rfid2="scope">
        {{ (scope.row.rfid && scope.row.rfid.length > 1)? scope.row.rfid[1]: '' }}
      </template>
      <template #table-highlight="scope">
        <el-tag :type="scope.row.highlight === 'connect' ? 'danger' : scope.row.highlight === 'hight' ? 'info' : 'success'" >
          {{scope.row.highlight === 'connect' ? '未连接' : scope.row.highlight === 'hight' ? '高电量' : '低电量' }}</el-tag>
      </template>
      <template #footerBtn="data">
        <el-button type="primary" @click="doSelectDownload" icon="el-icon-s-home" size="mini">选择行下载</el-button>
      </template>
      <template #headerSearch-btn-append="{ searchForm }">
        <el-button type="warning" size="small" icon="el-icon-download" @click="doDownload(searchForm)">托盘导出</el-button>
      </template>
    </vb-page>
  </div>
</template>

<script>
export default {
  data() {
    return {
      materialLoading: false,
      reloadMaterial: false,
      selection: null
    }
  },
  methods: {
    async doDownload(searchForm) {
      this.loading = true
      try {
        let res = await this.callApi('download_basic_tray_list', searchForm)
        if (!res.res) return
      } finally {
        this.loading = false
      }
    },
    doSelect(data) {
      this.selection = data
      console.log(data)
    },
    async doSelectDownload() {
      if (!this.selection || this.selection.length === 0) {
        this.$message.error('没有选择行')
        return
      }
      let trayList = []
      for(let i = 0; i < this.selection.length; i++) {
        trayList.push(this.selection[i])
      }
      try {
        await this.$confirm(`确定下载托盘信息吗`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
      } catch(e) {
        return
      }
      this.loading = true
      try {
        let res = await this.callApi('download_tray_list', { trayList: trayList })
        if (!res.res) {
          return
        }
        this.$message.success(`批量下载完成!`)
      } finally {
        this.loading = false
      }
    },
  }
}
</script>

<style scoped>

</style>
